package com.znyj.servlet.model;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;

import java.sql.Timestamp;

/**
 * Created by gaoliwei02 on 17/6/25.
 */
public class TaskQueryModel {
    private String group = "";
    private String order = "DESC";
    private int limit = 0;
    private int offset = 0;
    private int pageSize = 15;

    private String deviceId;
    private String userId;
    private long orderId;
    private String controlMsg;
    private Timestamp startTime;
    private Timestamp endTime;
    private int pageNumber = 0;

    public TaskQueryModel(String receiveData) {
        JSONObject receive = JSON.parseObject(receiveData);

        order = receive.getString("order");
        limit = receive.getInteger("limit");
        offset = receive.getInteger("offset");
        try {
            pageSize = Integer.parseInt(receive.getString("pageSize"));
        } catch (Exception e) {
            pageSize = -1;
        }
        try {
            pageNumber = receive.getInteger("pageNumber");
        } catch (Exception e) {
            pageNumber = offset / pageSize + 1;
        }

        deviceId = receive.getString("deviceId");
        userId = receive.getString("userId");
        controlMsg = receive.getString("controlMsg");

        try {
            startTime = Timestamp.valueOf(receive.getString("startTime"));
            endTime = Timestamp.valueOf(receive.getString("endTime"));
        } catch (Exception e) {

        }
        try {
            orderId = Long.parseLong(receive.getString("orderId"));
        } catch (Exception e) {
            orderId = -1;
        }


    }

    public String getOrder() {
        return order;
    }

    public void setOrder(String order) {
        this.order = order;
    }

    public String getGroup() {
        return group;
    }

    public void setGroup(String group) {
        this.group = group;
    }

    public int getOffset() {
        return offset;
    }

    public void setOffset(int offset) {
        this.offset = offset;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getLimit() {
        return limit;
    }

    public void setLimit(int limit) {
        this.limit = limit;
    }

    public int getPageNumber() {
        return pageNumber;
    }

    public void setPageNumber(int pageNumber) {
        this.pageNumber = pageNumber;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public String getDeviceId() {
        return deviceId;
    }

    public void setDeviceId(String deviceId) {
        this.deviceId = deviceId;
    }

    public long getOrderId() {
        return orderId;
    }

    public void setOrderId(long orderId) {
        this.orderId = orderId;
    }

    public String getControlMsg() {
        return controlMsg;
    }

    public void setControlMsg(String controlMsg) {
        this.controlMsg = controlMsg;
    }

    public Timestamp getStartTime() {
        return startTime;
    }

    public void setStartTime(Timestamp startTime) {
        this.startTime = startTime;
    }

    public Timestamp getEndTime() {
        return endTime;
    }

    public void setEndTime(Timestamp endTime) {
        this.endTime = endTime;
    }
//        @Override
//        public String toString() {
//            return "CommandLogQueryParam{" +
//                    "order='" + order + '\'' +
//                    ", group='" + group + '\'' +
//                    ", offset=" + offset +
//                    ", pageSize=" + pageSize +
//                    ", deviceId='" + deviceId + '\'' +
//                    ", uid='" + uid + '\'' +
//                    ", mid='" + mid + '\'' +
//                    ", mtAppkey='" + mtAppkey + '\'' +
//                    ", env='" + env + '\'' +
//                    ", messageAction='" + messageAction + '\'' +
//                    ", cmd='" + cmd + '\'' +
//                    ", startTime='" + startTime + '\'' +
//                    ", endTime='" + endTime + '\'' +
//                    '}';
//        }

}
